package com.yd.mvc.pc.jewellery.jewelleryPageController;

import com.yd.app.service.mobile.goodsService.MGoodsService;
import com.yd.app.service.mobile.goodsTypeService.MGoodsTypeService;
import com.yd.app.service.pc.jewellery.jewelleryPageService.WebSiteGoodsService;
import com.yd.app.util.BusinessException;
import com.yd.domain.business.GTypeOne;
import com.yd.domain.business.Goods;
import com.yd.domain.business.Pic;
import com.yd.domain.commom.PageModel;
import com.yd.domain.searchParam.GoodsSearchParam;
import com.yd.domain.sys.User;
import com.yd.mvc.baseController.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;

/**
 * @author zy
 * @create 2018-05-14 9:15
 * @desc 电脑前段商品展示
 **/
@RestController
@RequestMapping(value = "/api/webGoods")
public class WebSiteGoodsController extends BaseController{
    @Autowired
    private WebSiteGoodsService goodsService;

    /**
     * 商品信息列表
     * @param
     * @throws Exception
     */
    @RequestMapping(value = "/list/{pageIndex}/{pageSize}", method = RequestMethod.POST)
    public PageModel goodsList(@RequestBody GoodsSearchParam param, @PathVariable("pageIndex")int pageIndex, @PathVariable("pageSize")int pageSize)throws Exception {
        PageModel pm=goodsService.goodsList(param,pageIndex,pageSize);
        return pm;
    }
    /**
     * @Author: zy
     * @Desc: 查询商品导航三级
     * @Date:  2018/4/28
     * @Param
     */
    @RequestMapping(value = "/getGoodNav", method = RequestMethod.GET)
    public List<GTypeOne> getGoodNav() throws BusinessException {
        List<GTypeOne> list=goodsService.getGoodNav();
        return list;
    }
    /**
     * @Author: zy
     * @Desc: 查看产品详情
     * @Date:  2018/5/14
     * @Param
     */
    @RequestMapping(value = "/get/{goodsId}", method = RequestMethod.GET)
    public Goods getGoodsById(@PathVariable("goodsId")String goodsId) throws BusinessException {
        Goods goods=goodsService.getGoodsById(goodsId);
        return goods;
    }
    /**
     * @Author: zy
     * @Desc: 分页查询产品的评价信息
     * @Date:  2018/5/14
     * @Param
     */
    @RequestMapping(value = "/getList/{goodsId}/{pageIndex}/{pageSize}", method = RequestMethod.GET)
    public PageModel getEvaluateList(@PathVariable("goodsId") String goodsId, @PathVariable("pageIndex") int pageIndex, @PathVariable("pageSize") int pageSize) throws BusinessException {
        PageModel pageModel = null;
        try {
            pageModel = goodsService.getEvaluateList(goodsId, pageIndex, pageSize);
        } catch (Exception e) {
            throw new BusinessException(500, "获取评价信息失败");
        }
        return pageModel;
    }
    /**
     * @Author: zy
     * @Desc: 获取商品所有图片
     * @Date:  2018/5/14
     * @Param
     */
    @RequestMapping(value = "/getAllPic/{goodId}", method = RequestMethod.GET)
    public List<Pic> getAllPic(@PathVariable("goodId")String goodId){
        List<Pic> list=new ArrayList<>();
        list=goodsService.getAllPic(goodId);
        return list;
    }


}
